package com.exchange.util;


import java.io.Serializable;

/**
 * 控制器统一返回前端实体
 *
 * @author DENGLONG
 * @version 1.0
 * @create 2019-04-22 2:02 PM
 **/
public class ResponseData <T> implements Serializable {

    /**
     * 调用结果
     */
    private Integer code;

    /**
     * 调用是否成功
     */
    private boolean success;


    /**
     * 返回消息（错误信息）
     */
    private String message;

    /**
     * 返回数据
     */
    private T data;


    public static ResponseData init() {
        return new ResponseData(200, true);
    }

    /**
     * 系统级异常
     * @return
     */
    public static ResponseData error(){
        return new ResponseData(506, false);
    }

    /**
     * 登录失效
     * @return
     */
    public static ResponseData notLogin() {
        return new ResponseData(606, false);
    }

    /**
     * 未授权
     * @return
     */
    public static ResponseData unAuth() {
        return new ResponseData(401, false);
    }

    public ResponseData() {
    }

    /**
     * 构造方法
     * @param code
     * @param success
     */
    public ResponseData(Integer code, boolean success) {
        this.code = code;
        this.success = success;
    }

    public ResponseData(Integer code, boolean success, String message, T data) {
        this.code = code;
        this.success = success;
        this.message = message;
        this.data = data;
    }

    @Override
    public String toString() {
        return "ResponseData{" +
                "code=" + code +
                ", success=" + success +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
